package com.fumihiko.modules.sys.controller;

import cn.hutool.http.HttpRequest;
import com.fumihiko.common.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Style
 * @version 1.0
 * @date 2021/8/25
 **/
@Slf4j
@RestController
public class ApiController {

    /**
     * 日志service
     */
    /*@Autowired
    private SysLogService sysLogService;*/

    /**
     *
     */
    private String systemKey = "jb_sun";

    private String systemFlag = "yidong";

    private String preUrl = "http://39.98.62.88";

    private String url = "/caac/wfm/ApplicationController/completeWorkitem";

    /**
     * 公文流转
     *
     * @param data 表单数据
     * @return
     */
    @PostMapping("/completeWorkItem")
    public R completeWorkItem(@RequestParam String data){
        try {
            Map<String, Object> formMap = new HashMap<String, Object>();
            formMap.put("systemKey", systemKey);
            formMap.put("systemFlag", systemFlag);
            //data = "{'t':1629958023268,'fwForm':{'rowNum':null,'errorMsg':null,'fwId':'abd03f22703a4d2da09b17d9b119b405','fwBizType':'mhj_fw','title':'测试','drafterDeptName':'秘书处（行政审批服务处）','drafterName':'孙嘉槟','draftTime':'2021-07-30','statusName':null,'fwTypeName':null,'fwBizTypeName':null,'fwNum':null,'proInstId':'0708bdf2d218451d8da6c01bdbaf2ade','curActName':'综合司审核','fwType':null,'fwWordId':'a1a44dc9-f451-11eb-a039-cb2d5ace7f32','fwWord':'民航发','fwYear':null,'secrecyLevel':'1','secrecyReason':null,'secrecyPeriod':null,'emergencyLevel':'1','fwCode':null,'mainTo':'','copyTo':'','copyReports':null,'printFileNum':null,'drafterId':'9081','drafterDeptId':'001002007','drafterPhone':'','delFlag':'2','deleterId':'','delTime':null,'draftStatus':'2','completeTime':null,'status':'2','issuedStatus':null,'createTime':'2021-07-30','printDeptId':null,'infoDisclosure':'2','isLegality':null,'proofreadUserName':null,'proofreadTime':null,'composingUserName':null,'composingTime':null,'secrecyUserName':null,'secrecyTime':null,'officeCheckUserName':null,'officeCheckTime':null,'deptCheckUserName':null,'deptCheckTime':null,'messageShare':null,'remark':null,'nopublicReason':null,'storagePeriod':'1','sendStart':'','tzggStart':'','infoDisclosureType':null,'fileAttribute':'1','isSupervise':'1','cyqk':null,'psfs':'','description':'','isLegal':'0','isInterpret':'0','isPolicy':'0','countersign':'','xzsplgw':'2','endlineTime':null,'documentMap':null,'fwNumType':null,'extendIdForRelate':'c975f125f08000016ee36ab115908f70','printPartInstructions':null},'wfmData':{'configId':'68f6c3cf43aa466f899798691229159b','proDirId':'25ded9cc79b94329beffa78225a077c9','actDefId':'zhssh','proInstId':'0708bdf2d218451d8da6c01bdbaf2ade','actInstId':'7c7e67b901e142a692c46d9de393a249','workitemId':'6681b23765544bc188123c7f97896e56','nextActivities':[{'actDefId':'smszz','actDefName':'司秘书中转','proDefId':'mhjfwlc','actDefPath':'mhjfwlc,smszz','proDirId':'25ded9cc79b94329beffa78225a077c9','actInstId':null,'participants':'9945','selectPersonType':'checkbox','returnSelect':'false'}]}}";
            formMap.put("data", data);
            String result = HttpRequest.post(preUrl + url)
                                     .form(formMap)
                                     .execute().body();
            log.info("【返回报文：{}】", result);
            return R.ok();
        } catch (Exception e) {
            log.error("【公文流转接口请求失败, 系统异常】", e);
            return R.error();
        }
    }


}
